package org.grow.share.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class CorsTestFilter implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse) servletResponse;
        res.addHeader("Access-Control-Allow-Credentials",
                "true");
        res.addHeader("Access-Control-Allow-Origin",
                "*");
        res.addHeader("Access-Control-Allow-Methods",
                "GET, POST, DELETE, PUT, OPTIONS");
        res.addHeader("Access-Control-Allow-Headers",
                "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN");
        res.addHeader("Access-Control-Max-Age", "36000L");
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
